clear;
T = readtable('Input Data\Connections_byState.xlsx');
States = T.State;
N = T.Perc;
for i = 1:length(N)
    if N(i) <= 0.05
        N(i) = 0.05;
    elseif N(i) > 0.05 && N(i) <= 0.1
        N(i) = 0.1;
    elseif N(i) > 0.1 && N(i) <= 0.15
        N(i) = 0.15;
    elseif N(i) > 0.15 && N(i) <= 0.2
        N(i) = 0.2;
    elseif N(i) > 0.2 && N(i) <= 0.25
        N(i) = 0.25;
    elseif N(i) > 0.25 && N(i) <= 0.35
        N(i) = 0.3;
    elseif N(i) > 0.35 && N(i) <= 0.55
        N(i) = 0.35;
    end
end
N = 1-N;
bounds = [min(N) max(N)];


hFig = figure;
ax = usamap('all');
set(ax, 'Visible', 'off')

states1 = shaperead('usastatelo', 'UseGeoCoords', true);
for i = 1:numel(states1)
    for j = 1:length(States)
        if strcmp(States{j},states1(i).Name)
            states1(i).N = N(j);
        end
    end
end
states2 = shaperead('usastatelo', 'UseGeoCoords', true,'Selector',{@(name) ~any(strcmp(name,{'Alaska','Hawaii','District of Columbia'})), 'Name'});
for i = 1:numel(states2)
    for j = 1:length(States)
        if strcmp(States{j},states2(i).Name)
            states2(i).N = N(j);
        end
    end
end

names = {states1.Name};

indexHawaii = strcmp('Hawaii',names);
indexAlaska = strcmp('Alaska',names);

indexConus = 1:numel(states1);
indexConus(indexHawaii|indexAlaska) = [];

colors = [0     0   0;
          0.5   0   0;
          0.8   0   0;
          1     0 0;
          1     0.5 0.5;
          1     0.8 0.8;
          1     1   1];
faceColors1 = makesymbolspec('Polygon', {'N', [bounds(1,1) bounds(1,2)], 'FaceColor', colors});
faceColors2 = makesymbolspec('Polygon', {'N', [bounds(1,1) bounds(1,2)], 'FaceColor', colors});

geoshow(ax(1), states2, 'DisplayType', 'polygon', 'SymbolSpec', faceColors1)
geoshow(ax(2), states1(indexAlaska), 'DisplayType', 'polygon', 'SymbolSpec', faceColors1)
geoshow(ax(3), states1(indexHawaii), 'DisplayType', 'polygon', 'SymbolSpec', faceColors1)
for k = 1:3
    setm(ax(k), 'Frame', 'off', 'Grid', 'off',...
      'ParallelLabel', 'off', 'MeridianLabel', 'off')
end







hold on
bar(1,1,'FaceColor',colors(7,:));
bar(2,2,'FaceColor',colors(6,:));
bar(3,3,'FaceColor',colors(5,:));
bar(4,4,'FaceColor',colors(4,:));
bar(5,5,'FaceColor',colors(3,:));
bar(6,6,'FaceColor',colors(2,:));
bar(7,7,'FaceColor',colors(1,:));
color = [1,1,1];
set(gca,'XColor',color,'YColor',color,'TickDir','out')
legend('0% - 5%','5% - 10%','10% - 15%','15% - 20%','20% - 25%','25% - 35%',' > 35%')

set(gcf,'position',[17,42,1378,954])
print(gcf,'Figure2.tiff','-dtiff','-r300'); 